package com.tbit.main.util;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

/**
 * 指令工具类
 *
 * @author LMY
 * @create 2023-03-13 15:12
 */
public class ControlUtil {

    /**
     * 生成拍照参数
     *
     * @param uploadNow    是否立即上报 bit0
     *                     0：不上传       1：直接上传
     * @param qualityLevel 像素等级 bit1-2
     *                     0：低质量（默认）  1：中质量  2：高质量
     * @param cameraNo     摄像头编号 bit3-5
     *                     0：逆行，闯红灯，非机动车道
     *                     1：识别头盔，多人骑行
     *                     2：换车识别，站点角度识别
     * @return
     */
    public static String buildPhotoParam(int uploadNow, int qualityLevel, int cameraNo) {
        Integer i = 0;
        i |= cameraNo;
        i = i << 2;
        i |= qualityLevel;
        i = i << 1;
        i |= uploadNow;
        return i.toString();
    }


    public static Boolean helmetParam(String param) throws DecoderException {
        byte[] bytes = Hex.decodeHex(param);

        return ((bytes[9] & (1 << 4)) != 0);
    }

    public static void main(String[] args) throws DecoderException {

        /*byte[] bytes = Hex.decodeHex("000000000000002500100000");


        System.out.println(bytes[9] & (1 << 4));*/

        /**立刻上报，三种质量，三路摄像头*/
        System.out.println(buildPhotoParam(1, 0, 0));//1
        System.out.println(buildPhotoParam(1, 1, 0));//3
        System.out.println(buildPhotoParam(1, 2, 0));//5

        System.out.println(buildPhotoParam(1, 0, 1));//9
        System.out.println(buildPhotoParam(1, 1, 1));//11
        System.out.println(buildPhotoParam(1, 2, 1));//13

        System.out.println(buildPhotoParam(1, 0, 2));//17
        System.out.println(buildPhotoParam(1, 1, 2));//19
        System.out.println(buildPhotoParam(1, 2, 2));//21
    }
}
